var avatarUp0, avatarUp1, avatarUp2, avatarUp3, avatarUp4, avatarUp5,
    avatarUp6, avatarUp7, avatarUp8, avatarUp9, avatarUp10, avatarUp11, avatarUp50,
    avatarUp12, avatarUp13, avatarUp14, avatarUp15, avatarUp16, avatarUp17,
    avatarUp18, avatarUp19, avatarUp20, avatarUp21, avatarUp22, avatarUp95,
    avatarUp96, avatarUp97, avatarUp98, avatarUp99,avatarUp100, avatarUp94, avatarUp93 = "";

function iconTypeChange() {
    avatarUp0 = new $IconUpload("avatar0");
    avatarUp0.initIcon();
    avatarUp1 = new $IconUpload("avatar1");
    avatarUp1.initIcon();
    avatarUp2 = new $IconUpload("avatar2");
    avatarUp2.initIcon();
    avatarUp3 = new $IconUpload("avatar3");
    avatarUp3.initIcon();
    avatarUp4 = new $IconUpload("avatar4");
    avatarUp4.initIcon();
    avatarUp5 = new $IconUpload("avatar5");
    avatarUp5.initIcon();
    avatarUp6 = new $IconUpload("avatar6");
    avatarUp6.initIcon();
    avatarUp7 = new $IconUpload("avatar7");
    avatarUp7.initIcon();
    avatarUp8 = new $IconUpload("avatar8");
    avatarUp8.initIcon();
    avatarUp9 = new $IconUpload("avatar9");
    avatarUp9.initIcon();
    avatarUp10 = new $IconUpload("avatar10");
    avatarUp10.initIcon();
    avatarUp11 = new $IconUpload("avatar11");
    avatarUp11.initIcon();
    avatarUp12 = new $IconUpload("avatar12");
    avatarUp12.initIcon();
    avatarUp13 = new $IconUpload("avatar13");
    avatarUp13.initIcon();
    avatarUp50 = new $IconUpload("avatar50");
    avatarUp50.initIcon();
    avatarUp14 = new $IconUpload("avatar14");
    avatarUp14.initIcon();
    avatarUp15 = new $IconUpload("avatar15");
    avatarUp15.initIcon();
    avatarUp16 = new $IconUpload("avatar16");
    avatarUp16.initIcon();
    avatarUp17 = new $IconUpload("avatar17");
    avatarUp17.initIcon();
    avatarUp18 = new $IconUpload("avatar18");
    avatarUp18.initIcon();
    avatarUp19 = new $IconUpload("avatar19");
    avatarUp19.initIcon();
    avatarUp20 = new $IconUpload("avatar20");
    avatarUp20.initIcon();
    avatarUp21 = new $IconUpload("avatar21");
    avatarUp21.initIcon();
    avatarUp22 = new $IconUpload("avatar22");
    avatarUp22.initIcon();
    avatarUp93 = new $IconUpload("avatar93");
    avatarUp93.initIcon();
    avatarUp94 = new $IconUpload("avatar94");
    avatarUp94.initIcon();
    avatarUp95 = new $IconUpload("avatar95");
    avatarUp95.initIcon();
    avatarUp96 = new $IconUpload("avatar96");
    avatarUp96.initIcon();
    avatarUp97 = new $IconUpload("avatar97");
    avatarUp97.initIcon();
    avatarUp98 = new $IconUpload("avatar98");
    avatarUp98.initIcon();
    avatarUp99 = new $IconUpload("avatar99");
    avatarUp99.initIcon();
    avatarUp100 = new $IconUpload("avatar100");
    avatarUp100.initIcon();
}

$(function () {
    iconTypeChange();
    $("#first_Content_nav > div").eq(0).click();
    $("#orthodonticsAge").val($("#customerAgeValue",parent.document).val());
    $("#sex").val($("#sexValue",parent.document).val());
});

$("#first_Content_nav > div").click(function () {
    var index = $(this).index();
    $(this).addClass('selection').siblings().removeClass('selection');
    $("#first_Content_con > div").eq(index).show().siblings().hide();
    iconTypeChange();
});

function firstClose() {
    parent.layer.close(parent.layer.getFrameIndex(window.name));
}

function storageOrthodontics() {
    var reservationsId=window.parent.document.getElementById("reservationsId").value;
    var num=document.getElementById("num").value;
    var customerName=document.getElementById("customerName").value;
    var doctor = $("#doctor").val();
    var nurse = $("#nurse").val();
    var sex = $("#sex").val();
    var congestionDegree = $("#congestionDegree").val();
    var coveringCoverage = $("#coveringCoverage").val();
    var molarRelationship = $("#molarRelationship").val();
    var canineRelationship = $("#canineRelationship").val();
    var orthodonticDesign = $("#orthodonticDesign").val();
    var designScheme = $("#designScheme").val();
    var orthodonticsAge = $("#orthodonticsAge").val();
    if(doctor==null || doctor=="" || doctor==undefined){
        alert("请选择医生");
        return false;
    }
    if(nurse==null || nurse=="" || nurse==undefined){
        alert("请输入护士");
        return false;
    }
    $.ajax({
        url: Feng.ctxPath + "/doctorLooked/storageOrthodontics",
        type: "post",
        data: {
            "num": num,
            "sex": sex,
            "reservationsId": reservationsId,
            "doctor": doctor,
            "nurse": nurse,
            "customerName": customerName,
            "congestionDegree": congestionDegree,
            "coveringCoverage": coveringCoverage,
            "molarRelationship": molarRelationship,
            "canineRelationship": canineRelationship,
            "designScheme": designScheme,
            "orthodonticDesign": orthodonticDesign,
            "orthodonticsAge": orthodonticsAge
        },
        success: function (data) {
            Feng.success('操作成功!');
            window.parent.OrthodonticScoreTable.table.refresh();
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        }
    })
}

function subOrthodontics() {
    if($("#avatar0PreId").children().length <= 0 || $("#avatar1PreId").children().length <= 0 || $("#avatar2PreId").children().length <= 0
        || $("#avatar3PreId").children().length <= 0 || $("#avatar4PreId").children().length <= 0 || $("#avatar5PreId").children().length <= 0
        || $("#avatar6PreId").children().length <= 0 || $("#avatar7PreId").children().length <= 0 || $("#avatar8PreId").children().length <= 0
        || $("#avatar9PreId").children().length <= 0 || $("#avatar10PreId").children().length <= 0 || $("#avatar11PreId").children().length <= 0
        || $("#avatar12PreId").children().length <= 0 || $("#avatar13PreId").children().length <= 0 || $("#avatar14PreId").children().length <= 0
        || $("#avatar16PreId").children().length <= 0 || $("#avatar17PreId").children().length <= 0 || $("#avatar18PreId").children().length <= 0
        || $("#avatar19PreId").children().length <= 0 || $("#avatar20PreId").children().length <= 0 ||$("#avatar95PreId").children().length <= 0
        || $("#avatar50PreId").children().length <= 0 || $("#avatar96PreId").children().length <= 0 || $("#avatar97PreId").children().length <= 0
        || $("#avatar98PreId").children().length <= 0 || $("#avatar99PreId").children().length <= 0|| $("#avatar100PreId").children().length <= 0){
        Feng.error("请补全照片！");
        return false;
    }
    if($("#avatar21PreId").children().length <= 0 && $("#avatar22PreId").children().length <= 0 ){
        Feng.error("请补全照片！");
        return false;
    }
    var reservationsId=window.parent.document.getElementById("reservationsId").value;
    var medicalRecordNumberValue=window.parent.document.getElementById("medicalRecordNumberValue").value;
    var num=document.getElementById("num").value;
    var customerName=document.getElementById("customerName").value;
    var doctor = $("#doctor").val();
    var nurse = $("#nurse").val();
    var sex = $("#sex").val();
    var congestionDegree = $("#congestionDegree").val();
    var coveringCoverage = $("#coveringCoverage").val();
    var molarRelationship = $("#molarRelationship").val();
    var canineRelationship = $("#canineRelationship").val();
    var orthodonticDesign = $("#orthodonticDesign").val();
    var designScheme = $("#designScheme").val();
    var orthodonticsAge = $("#orthodonticsAge").val();
    if(doctor==null || doctor=="" || doctor==undefined){
        alert("请选择医生");
        return false;
    }
    if(nurse==null || nurse=="" || nurse==undefined){
        alert("请输入护士");
        return false;
    }
    if(congestionDegree == null || congestionDegree == undefined || congestionDegree == ""){
        alert("请填写拥挤度");
        return false;
    }
    if(coveringCoverage == null || coveringCoverage == undefined || coveringCoverage == ""){
        alert("请填写覆合覆盖");
        return false;
    }
    if(molarRelationship == null || molarRelationship == undefined || molarRelationship == ""){
        alert("请填写磨牙关系");
        return false;
    }
    if(canineRelationship == null || canineRelationship == undefined || canineRelationship == ""){
        alert("请填写尖牙关系");
        return false;
    }
    if(orthodonticDesign == null || orthodonticDesign == undefined || orthodonticDesign == ""){
        alert("请填写矫治原则");
        return false;
    }
    if(designScheme == null || designScheme == undefined || designScheme == ""){
        alert("请填写设计方案");
        return false;
    }
    $.ajax({
        url: Feng.ctxPath + "/doctorLooked/subOrthodontics",
        type: "post",
        data: {
            "reservationsId": reservationsId,
            "num": num,
            "sex": sex,
            "doctor": doctor,
            "nurse": nurse,
            "customerName": customerName,
            "congestionDegree": congestionDegree,
            "coveringCoverage": coveringCoverage,
            "molarRelationship": molarRelationship,
            "canineRelationship": canineRelationship,
            "designScheme": designScheme,
            "orthodonticsAge": orthodonticsAge,
            "orthodonticDesign": orthodonticDesign,
            "medicalRecordNumberValue":medicalRecordNumberValue
        },
        success: function (data) {
            Feng.success('操作成功!');
            window.parent.OrthodonticScoreTable.table.refresh();
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        }
    })
}

function subOrthodonticsds() {
    var reservationsId=window.parent.document.getElementById("reservationsId").value;
    var medicalRecordNumberValue=window.parent.document.getElementById("medicalRecordNumberValue").value;
    var num=document.getElementById("num").value;
    var customerName=document.getElementById("customerName").value;
    var doctor = $("#doctor").val();
    var nurse = $("#nurse").val();
    var sex = $("#sex").val();
    var congestionDegree = $("#congestionDegree").val();
    var coveringCoverage = $("#coveringCoverage").val();
    var molarRelationship = $("#molarRelationship").val();
    var canineRelationship = $("#canineRelationship").val();
    var orthodonticDesign = $("#orthodonticDesign").val();
    var designScheme = $("#designScheme").val();
    var orthodonticsAge = $("#orthodonticsAge").val();
    if(doctor==null || doctor=="" || doctor==undefined){
        alert("请选择医生");
        return false;
    }
    if(nurse==null || nurse=="" || nurse==undefined){
        alert("请输入护士");
        return false;
    }
    if(checkIsTime()){
        $.ajax({
            url: Feng.ctxPath + "/doctorLooked/subOrthodontics2",
            type: "post",
            data: {
                "reservationsId": reservationsId,
                "num": num,
                "sex": sex,
                "doctor": doctor,
                "nurse": nurse,
                "customerName": customerName,
                "congestionDegree": congestionDegree,
                "coveringCoverage": coveringCoverage,
                "molarRelationship": molarRelationship,
                "canineRelationship": canineRelationship,
                "orthodonticDesign": orthodonticDesign,
                "designScheme": designScheme,
                "orthodonticsAge": orthodonticsAge,
                "medicalRecordNumberValue":medicalRecordNumberValue

            },
            success: function (data) {
                Feng.success('操作成功!');
                window.parent.OrthodonticScoreTable.table.refresh();
                parent.layer.close(parent.layer.getFrameIndex(window.name));
            }
        })
    }else{
        if($("#avatar0PreId").children().length <= 0 || $("#avatar1PreId").children().length <= 0 || $("#avatar2PreId").children().length <= 0
            || $("#avatar3PreId").children().length <= 0 || $("#avatar4PreId").children().length <= 0 || $("#avatar5PreId").children().length <= 0
            || $("#avatar6PreId").children().length <= 0 || $("#avatar7PreId").children().length <= 0 || $("#avatar8PreId").children().length <= 0
            || $("#avatar9PreId").children().length <= 0 || $("#avatar10PreId").children().length <= 0 || $("#avatar11PreId").children().length <= 0
            || $("#avatar12PreId").children().length <= 0 || $("#avatar13PreId").children().length <= 0 || $("#avatar14PreId").children().length <= 0
            || $("#avatar95PreId").children().length <= 0 || $("#avatar50PreId").children().length <= 0
            || $("#avatar96PreId").children().length <= 0 || $("#avatar97PreId").children().length <= 0 || $("#avatar98PreId").children().length <= 0
            || $("#avatar99PreId").children().length <= 0 || $("#avatar100PreId").children().length <= 0){
            Feng.error("请补全照片！");
            return false;
        }
        if($("#avatar21PreId").children().length <= 0 && $("#avatar22PreId").children().length <= 0 ){
            Feng.error("请补全照片！");
            return false;
        }
        $.ajax({
            url: Feng.ctxPath + "/doctorLooked/subOrthodontics",
            type: "post",
            data: {
                "reservationsId": reservationsId,
                "num": num,
                "sex": sex,
                "doctor": doctor,
                "nurse": nurse,
                "customerName": customerName,
                "congestionDegree": congestionDegree,
                "coveringCoverage": coveringCoverage,
                "molarRelationship": molarRelationship,
                "canineRelationship": canineRelationship,
                "designScheme": designScheme,
                "orthodonticsAge": orthodonticsAge,
                "medicalRecordNumberValue":medicalRecordNumberValue
            },
            success: function (data) {
                Feng.success('操作成功!');
                window.parent.OrthodonticScoreTable.table.refresh();
                parent.layer.close(parent.layer.getFrameIndex(window.name));
            }
        })
    }
}

function checkIsTime() {
    var arrivalTime = $("#arrivalTimeValue").val();
    var arrTime =new Date(Date.parse(arrivalTime .replace('/-/g','/'))).getTime();
    var curTime  = '2019-10-16';
    var strTime = new Date(Date.parse(curTime .replace('/-/g','/'))).getTime();
    if (arrTime - strTime <0) {
        return true;
    } else {
        return false;
    }
};

$("#avatar0PreId,#avatar1PreId,#avatar2PreId,#avatar3PreId,#avatar4PreId,#avatar5PreId,#avatar6PreId,#avatar7PreId,#avatar8PreId,#avatar9PreId," +
    "#avatar10PreId,#avatar11PreId,#avatar12PreId,#avatar13PreId,#avatar14PreId,#avatar15PreId,#avatar16PreId,#avatar17PreId," +
    "#avatar18PreId,#avatar19PreId,#avatar20PreId,#avatar21PreId,#avatar22PreId,#avatar50PreId").on('click', '.cp_img_delete', function (e) {
    e.stopPropagation();
    var that = this;
    var id = $(that).parent().attr("id");
    $.ajax({
        url: Feng.ctxPath + "/doctorLooked/deleteOrthodonticsImgs",
        type: "post",
        data: {"id": id},
        success: function (data) {
            $(that).parent().parent().siblings().css({'pointer-events': 'auto', 'cursor': 'pointer', 'background': 'white'});
            $(that).parent().remove();
            Feng.success("删除成功！");
        },
        error: function (data) {
            alert("删除失败！");
        }
    });
});

$("#avatar100PreId,#avatar99PreId,#avatar98PreId,#avatar97PreId,#avatar96PreId,#avatar95PreId").on('click', '.cp_img_delete', function (e) {
    e.stopPropagation();
    var that = this;
    var id = $(that).parent().attr("id");
    $.ajax({
        url: Feng.ctxPath + "/doctorLooked/deleteOrthodonticsImgs",
        type: "post",
        data: {"id": id},
        success: function (data) {
            $(that).parent().parent().siblings().children().css({'pointer-events': 'auto', 'cursor': 'pointer', 'background': 'white'});
            $(that).parent().remove();
            Feng.success("删除成功！");
        },
        error: function (data) {
            alert("删除失败！");
        }
    });
});